#ifndef CLIENTMANAGER_H
#define CLIENTMANAGER_H

#include <QMutex>
#include <QByteArray>
#include <QUdpSocket>
#include <QSet>
#include <QHostAddress>


/**
 * @brief 管理客户端
 */
class ClientManager
{
public:
    /**
     * @brief 单例
     * @return
     */
    static ClientManager & getInstance();

    /**
     * @brief 添加客户端
     * @param task
     */
    void addClient(QHostAddress ip, quint16 port);

    /**
     * @brief sendData
     * @param arr
     */
    void sendData(QUdpSocket & udp ,const QByteArray &arr);


    /**
     * @brief 客户端个数
     * @return
     */
    int clientCount();

    /**
     * @brief 关闭所有客户端
     */
    void closeAllClients();

    typedef std::pair<QHostAddress , quint16> ClientInfo;

private:
    ClientManager(){}
    Q_DISABLE_COPY(ClientManager);

private:
    static ClientManager * m_instance;
    static QMutex m_mutex;

    //QSet 就是集合， 元素不能重复
    QSet< QPair<QHostAddress , quint16>>  m_clientList;
};

#endif // CLIENTMANAGER_H
